package com.ubst.smartad.impl.admin.work;

import java.sql.*;
import java.util.*;
import java.io.*;

import com.ubst.smartad.common.TimeUtil;
import com.ubst.smartad.logger.Debug;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class WorkMngImpl {
	
	Connection con = null;
	private String serverName;
	private Debug debug;
	//private FileHostEnv fhostEnv;


    /** 
     * 생성자
     *   
     *   
    */ 
	public WorkMngImpl(Connection con, String serverName, String log_level) {
		this.con = con;
		this.serverName = serverName;
		this.debug = new Debug("WorkMngImpl", log_level);
		//this.fhostEnv = FileHostEnv.getInstance(serverName);

	}

	
	/**
	 *  @author Kswany
	 * 	Work(작업) - Work jqGrid List 가져오기
	 * 
	 *  searchStr: 검색조건
	 *  orderBy: sort조건
	 *  prev_page: first limit 
	 *  next_page: last limit
	 *  
	 * **/
	public List getJqgridWorkList(String searchStr, String orderBy, int prev_page, int next_page) 
//			throws SQLException{
			throws Exception{
		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_data_map = null;
		List log_datas = new ArrayList();
		
		try{
		/*
		 *  DB value 값세팅 구현 로직 들어갈 부분
		 */
		// 가상데이터
		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("work_no", "2");
		log_data_map.put("system_name", "window");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "예약완료");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "3");
		log_data_map.put("system_name", "sol");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "미완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "4");
		log_data_map.put("system_name", "linux");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "5");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("work_no", "1");
		log_data_map.put("system_name", "redhat");
		log_data_map.put("work_ex", "리눅스계정수집");
		log_data_map.put("reservation_yn", "취소");
		log_data_map.put("result", "완료");
		log_data_map.put("run_time", "2013-05-17 16:11:11");
		log_datas.add(log_data_map);
		

	//	}catch (SQLException e){
		}catch (Exception e){
			throw e;
		}finally{
	//		if ( rs != null) try{rs.close();}catch(SQLException ee){}
	//		if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
	
		return log_datas;
	}
	
	/**
	 *  @author Kswany
	 * 	Work(작업) - Work jqGrid Log List 가져오기
	 * 
	 *  searchStr: 검색조건
	 *  orderBy: sort조건
	 *  prev_page: first limit 
	 *  next_page: last limit
	 *  
	 * **/
	public List getJqgridWorkLogList(String searchStr, String orderBy, int prev_page, int next_page) 
//			throws SQLException{
			throws Exception{
		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_data_map = null;
		List log_datas = new ArrayList();
		
		try{	
		/*
		 *  DB value 값세팅 구현 로직 들어갈 부분
		 */
		// 가상데이터
		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-12 23:52:11");
		log_data_map.put("type", "계정관리22");
		log_data_map.put("work", "계정정책 변경22");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보22");
		log_data_map.put("worker", "adadmin22");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리33");
		log_data_map.put("work", "계정정책 변경33");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보33");
		log_data_map.put("worker", "adadmin33");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리44");
		log_data_map.put("work", "계정정책 변경44");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보44");
		log_data_map.put("worker", "adadmin44");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

		log_data_map = new HashMap();
		log_data_map.put("calender", "2013-01-13 22:52:01");
		log_data_map.put("type", "계정관리");
		log_data_map.put("work", "계정정책 변경");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
	//	}catch (SQLException e){
		}catch (Exception e){
			throw e;
		}finally{
	//		if ( rs != null) try{rs.close();}catch(SQLException ee){}
	//		if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
	
		return log_datas;
	}
	
	/**
	 * @author : Kswany 
	 * Work(작업) - Work Info 가져오기 View
	 *	key: system_name(가상설정)
	 */
	public HashMap getWorkInfo(String work_no) 
//			throws SQLException {
			throws Exception{

		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_info_map = new HashMap();

		try {

			/*
			 *  DB value 값세팅 구현 로직 들어갈 부분
			 */
			// 가상데이터
			log_info_map.put("system_name", "redhat");
			log_info_map.put("work_kind", "전체 정보 수집");
			log_info_map.put("target_account", "test01");
			log_info_map.put("work_cycle", "시간");
			log_info_map.put("work_number", "3");
			log_info_map.put("standard_time", "0분");
			log_info_map.put("work_ex", "리눅스 계정수집");
			log_info_map.put("reservation_status", "예약");
			log_info_map.put("work_complet", "실패");
			log_info_map.put("last_work_time", "2013-04-02 16:11:18");

		}catch (Exception e){
			throw e;
		}finally{
//			if ( rs != null) try{rs.close();}catch(SQLException ee){}
//			if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
		
		
		return log_info_map;
	}
	
	
	/**
	 * @author : Kswany 
	 * Work(작업) - Work Log 클릭시 Popup창으로 Info 가져오기
	 *	key: ip_addr(가상설정)
	 */
	public HashMap work_detail(String ip_addr) 
//			throws SQLException {
			throws Exception{

		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_info_map = new HashMap();

		try {

			/*
			 *  DB value 값세팅 구현 로직 들어갈 부분
			 */
			// 가상데이터
			log_info_map.put("log_time", "2013-05-03 09:50:03");
			log_info_map.put("log_type", "계정관리");
			log_info_map.put("work_type", "계정정책 변경");
			log_info_map.put("user", "adadmin");
			log_info_map.put("account", "test1234");
			log_info_map.put("ip_addr", "192.168.1.1");
			log_info_map.put("target_system", "IDMServer");
			log_info_map.put("service", "webadmin");
			log_info_map.put("result", "실패");
			log_info_map.put("detail", "상세내역입니다");

		}catch (Exception e){
			throw e;
		}finally{
//			if ( rs != null) try{rs.close();}catch(SQLException ee){}
//			if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
		
		
		return log_info_map;
	}
	
	
	/**
	 * @author : Kswany 
	 * Work(작업) - Work insert
	 *	key: system_name(가상설정)
	 */
	public boolean insertWorkAdd(HashMap param) 
//			throws SQLException {
			throws Exception{

		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_info_map = new HashMap();
		boolean result = false;
		try {

			String work_ex = String.valueOf(param.get("work_ex"));
			String work_kind = String.valueOf(param.get("work_kind"));
			String target_account = String.valueOf(param.get("target_account"));
			String password = String.valueOf(param.get("password"));
			String pw_check = String.valueOf(param.get("pw_check"));
			String work_cycle = String.valueOf(param.get("work_cycle"));
			String work_count = String.valueOf(param.get("work_count"));
			String standard_time1 = String.valueOf(param.get("standard_time1"));
		
			/*
			 *  DB value 값세팅 구현 로직 들어갈 부분
			 */
			// 가상데이터
			result = true;

		}catch (Exception e){
			throw e;
		}finally{
//			if ( rs != null) try{rs.close();}catch(SQLException ee){}
//			if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
		return result;
	}
	
	
	/**
	 * @author : Kswany 
	 * Work(작업) - Work delete(list checkbox선택후 삭제, 리스트 마지막으로 클릭 한 상세정보에서 삭제)
	 *	key: system_name(가상설정)
	 */
	public boolean deleteWork(List array) 
//			throws SQLException {
			throws Exception{

		PreparedStatement pstmt=null;
		ResultSet rs = null;

		boolean result = false;
		try {
	
			/*
			 *  DB value 값세팅 구현 로직 들어갈 부분(list의 key값들  where 조건 대입하여 삭제)
			 */
			// 가상데이터
			result = true;

		}catch (Exception e){
			throw e;
		}finally{
//			if ( rs != null) try{rs.close();}catch(SQLException ee){}
//			if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
		return result;
	}
	
	
	/**
	 * @author : Kswany 
	 * Work(작업) - Work insertWorkInfo
	 *	key: work_no(가상설정)
	 */
	public boolean insertWorkInfo(String work_no) 
//			throws SQLException {
			throws Exception{

		PreparedStatement pstmt=null;
		ResultSet rs = null;

		boolean result = false;
		try {

			/*
			 *  DB value 값세팅 구현 로직 들어갈 부분
			 */
			// 가상데이터
			result = true;

		}catch (Exception e){
			throw e;
		}finally{
//			if ( rs != null) try{rs.close();}catch(SQLException ee){}
//			if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
		return result;
	}
}
